package com.cwnu.mapper;

import com.cwnu.entity.Category;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Select("select * from category where category_name = #{categoryName};")
    Category findByCategoryName(String categoryName);

    @Insert("insert into category(category_name, create_id) values(#{categoryName}, #{createId});")
    void add(@RequestParam String categoryName, Integer createId);

    @Select("select * from category where category_name = #{categoryName} and create_id = #{id};")
    Category findByNameAndId(String categoryName, Integer id);

    @Update("update category set category_name = #{newName} where id = #{id};")
    void updateCategory(Integer id, String newName);

    @Delete("delete from category where id = #{id};")
    void deleteCategory(Integer id);

    @Select("select * from category where create_id = #{userId};")
    List<Category> getCategory(Integer userId);

    @Select("select * from category;")
    List<Category> getAllCategory();
}
